const express = require('express')
const path = require('path')
const app = express()
const router = require('./router/index')

//引入中间件让req.body以对象格式显示
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

// 设置响应头允许跨域请求
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Access-Control-Allow-Methods', '*');
  res.header('Content-Type', 'application/json;charset=utf-8');
  next();
});

// 引入接口
app.use(router)

// 监听3030端口
app.listen(3030, () => {
  console.log('服务器已启动')
})